<!-- 订单 -->
<template>
  <div class="list-container">
    <div class="main" v-show="listshow">
      <div class="filter ">
        <!-- <van-search v-model="input" shape="round" type="tel" @input="heanlesearch" @cancel="onCancel" placeholder="请输入手机号查询"
          @focus='heanleinputfocus' @blur='heanleinputblur' />
        </van-search> -->
        <van-search v-model="input" show-action placeholder="请输入收货人手机号码进行查询">
          <template #action>
            <van-button type="warning" size="small" round @click="heanleinputblur">搜索</van-button>
          </template>
        </van-search>
      </div>
      <div class="mianlist" v-if='orderList&&orderList.length'>
        <div v-for="(item,index) in orderList" :key="index" class="mianlist-item" @click="handleOrderdetails(item)">
          <div class="xmbzNo">订单号：{{item.xmbzNo}}</div>
          <div class="ordermain">
            <!-- <span>下单时间：{{item.createTime}}</span> -->
            <!-- <span>收货地址：{{item.receiverAddress}}</span> -->
          <!--  <van-field v-model="item.createTime" input-align="left" label="下单时间:" autosize type="textarea"
              rows="1" readonly class="receiverAddress"/> -->
            <van-field v-model="item.createTime" input-align="left" label="收货地址:" autosize type="textarea"
                rows="1" readonly class="receiverAddress"/>
            <van-field v-model="item.receiverAddress" input-align="left" label="收货地址:" autosize type="textarea"
              rows="1" readonly class="receiverAddress"/>
          </div>
        </div>
      </div>
      <div class="mainlistno" v-else>
        <div class="nodata" v-show="orderListnoshow">
          <img :src="nolist" alt="">
          <p class="tips">未查到订单记录</p>
        </div>
        <div class="bottomNodata">
          <div>熊猫不走·蛋糕</div>
          <concatService></concatService>
        </div>
      </div>
    </div>
    <!-- 如果手机号没有缓存 会进入登录弹窗 -->
    <van-popup v-model="loginshow" position="bottom" style="height:100%">
      <Login :tel='tel' @personsumbit='personsumbit' @headleBackorders='headleBackorders'></Login>
    </van-popup>
    <!-- 详情 -->
    <van-popup v-model="orderdetailShow" position="bottom" style="height:100%">
      <div class="about-container">
        <div class="main">
          <div class="mainlist" v-if="details&&details.length">
            <div class="listmain" v-show="orderListshow">
              <div class="orderstatus">{{orderList.status}}
                <van-icon class='cross' name="cross" @click="headleBackorder" />
              </div>
              <div class="order_address">
                <div class="left">
                  <img :src="postions" alt="">
                </div>

                <div class="right">
                  <div class="info">
                    <div class="name">{{orderList.receiverName}}</div>~
                    <div class="tel">{{orderList.bookerPhone}}</div>
                  </div>
                  <div class="address">{{orderList.receiverAddress}}</div>
                </div>
              </div>
              <div class="order_main">
                <ul class="cakelist">
                  <li v-for="child in orderList.details" :key="child.id">
                    <img :src="child.imgUrl" class="cakeimg" alt="">
                    <div class="cakename">{{ child.marketName }}</div>
                  </li>
                </ul>
                <div class="order_info">
                  <div class="order-item">
                    <span class="title">祝福语</span>
                    <span>{{orderList.blessings}}</span>
                  </div>
                  <div class="order-item">
                    <span class="title">配送时间</span>
                    <span style="text-align: right;font-size: 12px;">{{orderList.deliveryStartTime}}→{{orderList.deliveryEndTime}}</span>
                  </div>
                  <div class="order-item">
                    <van-field v-model="orderList.consumerRemark" input-align="left" label="备注" autosize type="textarea"
                      rows="1" readonly />
                  </div>
                  <div class="line"></div>
                  <div class="order-item">
                    <span class="title odernum">订单号</span>
                    <div>
                      <span class="copyObj" style="padding-right:8px">{{orderList.xmbzNo}}</span>
                      <span class="ordernum_read" @click="headerCopy(orderList.xmbzNo)">复制</span>
                    </div>
                  </div>
                  <div class="order-item">
                    <span class="title orderTime">下单时间</span>
                    <span>{{orderList.orderTime}}</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="bottom">
              <div>熊猫不走·蛋糕</div>
              <concatService></concatService>
            </div>
          </div>
          <div class="mainlist" v-else>
            <div class="nodata" v-show="orderListnoshow">
              <img :src="nolist" alt="">
              <p class="tips">未查到订单记录</p>
            </div>
            <div class="bottomNodata">
              <div>熊猫不走·蛋糕</div>
              <concatService></concatService>
            </div>
          </div>
        </div>

      </div>
      <!-- <orderdetails @headleBackorder='headleBackorder' :xmbzNos='xmbzNos'></orderdetails> -->
    </van-popup>

  </div>
</template>
<script>
  import nolist from '@/assets/image/list_no.png'
  import postions from '@/assets/image/postions.png'
  import {
    getOrderById,
    getOrderList,
    setCookie,
    getCookie,
    delCookie,
    getCaptcha
  } from '@/api/index'
  import Login from '@/components/login'
  import orderdetails from '@/components/orderdetails'
  export default {
    components: {
      Login,
      orderdetails
    },
    data() {
      return {
        nolist,
        postions,
        input: '',
        hidShow: false, //
        loginshow: false, // 登录弹窗
        tel: '',
        xmbzNos: '',

        // 订单列表
        orderList: [],
        listshow: true,
        details: '',
        orderListshow: false,
        orderListnoshow: true,
        orderdetailShow: false,
      }
    },
    watch: {},
    mounted() {
      this.getaboutorderList();
    },
    methods: {
      heanlesearch() {
        // this.loginshow=true
        // this.getaboutorderList()
      },
      heanleinputfocus() {

      },
      heanleinputblur(e) {
        let phone = getCookie("phone");
        if (this.input != phone) {
          if (this.input == '') {
            this.$toast({
              overlay: true,
              message: '请输入手机号',
              duration: 2000
            })
          } else if (!this.checkMobile(this.input)) {
            this.$toast({
              overlay: true,
              message: '手机号格式不正确',
              duration: 2000
            })
          } else {
            this.tel = this.input;
            this.loginshow = true
            // _czc.push('_setCustomVar','搜索订单','记录一次')
          }
        } else {
          this.$toast({
            overlay: true,
            message: '该手机号已存在订单数据',
            duration: 2000
          })
        }

        window.scroll(0, 0);
      },
      handleClose() {
        this.loginshow = false
      },
      getaboutorderList() {
        let phone = getCookie("phone");
        if (getCookie("phone")) {
          const params = {
            phone: getCookie("phone"),
            phoneToken: getCookie("phoneToken")
          }
          getOrderList(params).then(res => {
            if (res.code==400){
              this.$toast({
                overlay: true,
                message: res.msg,
                duration: 2000
              })
              this.orderListnoshow = true
              this.orderListshow = false
              return;
            }

            this.orderList = res.data
            this.details = res.data.details
            if (this.details && this.details.length > 0) {
              this.orderListnoshow = false
              this.orderListshow = true
            } else {
              this.orderListnoshow = true
              this.orderListshow = false
            }
          })
        } else {
          this.orderListnoshow = true;
          this.orderListshow = false
        }

      },
      personsumbit() {
        this.loginshow = false;
        this.getaboutorderList();
      },
      headleBackorder() {
        this.orderdetailShow = false
        this.getaboutorderList();
      },
      headleBackorders() {
        this.loginshow = false
        this.getaboutorderList();
      },
      onCancel() {
        this.orderListnoshow = true
        this.orderListshow = false
      },


      // 验证手机号
      checkMobile(str) {
        let re = /^1\d{10}$/;
        if (re.test(str)) {
          return true;
        } else {
          return false;
        }
      },
      headerCopy(link) {
        this.copy(link)
      },
      copy(data) {
        let url = data
        let oInput = document.createElement('input')
        oInput.value = data
        document.body.appendChild(oInput)
        oInput.select() // 选择对象;
        document.execCommand('Copy') // 执行浏览器复制命令
        this.$toast({
          overlay: true,
          message: '复制成功',
          duration: 2000
        })
        oInput.remove()
      },

      //进入详情
      handleOrderdetails(item) {
        this.xmbzNos = item.id;
        this.orderdetailShow = true;
        getOrderById({
          orderId: this.xmbzNos
        }).then(res => {
          this.orderList = res.data
          this.details = res.data.details
          if (this.details && this.details.length > 0) {
            this.orderListnoshow = false
            this.orderListshow = true
          } else {
            this.orderListnoshow = true
            this.orderListshow = false
          }
        })
        // this.$router.push({
        //   path: '/orderdetails',
        //   query: {
        //     //传参
        //     id: this.$route.query.id,
        //     type: this.$route.query.type,
        //     orderID: item.xmbzNo,
        //   }
        // })
      }
    }
  }
</script>

<style lang="scss">
  .van-search__content {
    border-radius: 50px;
  }

  .list-container {
    box-sizing: border-box;
    overflow: hidden;

    .main {
      .filter {
        position: fixed;
        top: 0;
        height: 50px;
        width: 100%;

      }

      .mianlist {
        padding-top: 60px;
        box-sizing: border-box;

        .mianlist-item {
          // height: 80px;
          padding-top: 15px;
          margin: auto;
          border-radius: 5px;
          margin-bottom: 10px;
          background-color: rgba(255, 255, 255, 1);
          color: rgba(16, 16, 16, 1);
          font-size: 14px;
          text-align: left;
          box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.09);
          font-family: Roboto;
          border: 1px solid rgba(255, 255, 255, 0);
          margin-bottom: 20px;

          .xmbzNo {
            color: rgba(153, 153, 153, 1);
            font-size: 12px;
            margin-bottom: 10px;
            border-left: 4px solid #3E97FC;
            padding-left: 10px;
          }

          .ordermain {
            padding: 0 15px;

            .receiverAddress{
              padding: 0!important;
              .van-field__label{
                width: 60px;
              }
            }

            span {
              display: block;
              line-height: 24px;
              color: rgba(55, 57, 55, 1);
              font-size: 12px;
            }
          }
        }


      }

      .mainlistno {
        .nodata {
          padding-top: 82px;

          img {
            width: 125px;
            height: 106px;
            margin: auto;
            display: block;
          }

          .tips {
            font-size: 16px;
            color: #767676;
            line-height: 22px;
            text-align: center;
          }
        }

        
      }

    }
  }

  .bottomNodata {
    position: absolute;
    bottom: 50px;
    font-weight: 400;
    text-align: center;
    font-size: 0.42667rem;
    color: #fc6f00;
    left: 0;
    right: 0;
    background: #fff;
    line-height: 36px;
    margin-bottom: 5px;

    .tips {
      font-size: 14px;
      color: rgba(105, 105, 105, 1);
    }
  }


  .about-container {
    box-sizing: border-box;
    overflow: hidden;

    .filter {
      position: fixed;
      top: 0;
      height: 50px;
      width: 100%;

    }

    .main {
      box-sizing: border-box;

      .mainlist {
        .bottom {
          // position: fixed;
          // bottom: 50px;
          font-weight: 400;
          text-align: center;
          font-size: 0.42667rem;
          color: #fc6f00;
          left: 0;
          right: 0;
          background: #fff;
          line-height: 36px;

          .tips {
            font-size: 14px;
            color: rgba(105, 105, 105, 1);
          }
        }

        .listmain {
          margin-bottom: 10px;

          .orderstatus {
            height: 65px;
            background: rgba(252, 214, 0, 1);
            font-size: 14px;
            line-height: 65px;
            padding-left: 16px;
            position: relative;

            .cross {
              position: absolute;
              right: 10px;
              top: 20px;

            }
          }

          .order_address {
            display: flex;
            border-bottom: 6px solid #e6e6e6;
            padding: 15px 18px;
            box-sizing: border-box;

            .left {
              width: 30px;
              position: relative;

              img {
                width: 18px;
                position: absolute;
                top: 10px;
              }
            }

            .right {
              .info {
                display: flex;
                font-size: 14px;
                line-height: 20px;
                margin-bottom: 4px;
              }

              font-size: 12px;
            }
          }

          .order_main {
            .cakelist {
              display: flex;
              flex-wrap: wrap;
              justify-content: space-between;
              padding: 15px;

              li {
                flex: 1;
                width: 161px;
                min-width: 161px; // 加入这两个后每个item的宽度就生效了
                max-width: 161px; // 加入这两个后每个item的宽度就生效了
                height: 200px;
                background: rgba(255, 255, 255, 1);
                box-shadow: 0px 2px 4px 0px rgba(209, 209, 209, 0.5), 0px -2px 4px 0px rgba(224, 224, 224, 0.5);
                border-radius: 6px;
                overflow: hidden;
                margin-bottom: 22px;

                .cakeimg {
                  width: 161px;
                  height: 147px;
                }

                .cakename {
                  padding: 6px 12px;
                  display: block;
                  overflow: hidden;
                  height: 32px;
                  text-overflow: ellipsis;
                  display: -webkit-box; //作为弹性伸缩盒子模型显示。
                  -webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
                  -webkit-line-clamp: 3; //显示的行
                }
              }
            }

            .order_info {
              box-sizing: border-box;
              font-size: 0.37333rem;
              width: 100%;

              .order-item {
                .title {
                  width: 80px;

                  &.odernum,
                  &.orderTime {
                    color: #6c6c6c;
                  }
                }

                .van-cell {
                  padding: 0 !important;
                }

                display: flex;
                justify-content: space-between;
                border-bottom: 1px solid #f2f2f2;
                padding: 0.26667rem 0.42667rem;

                .ordernum_read {
                  color: #fc6f00;
                  font-size: 14px;
                  border-left: 1px solid #ccc;
                  padding-left: 8px;
                }
              }

              .line {
                height: 6px;
                background: #e6e6e6;
              }
            }
          }
        }

        .nodata {
          padding-top: 82px;

          img {
            width: 125px;
            height: 106px;
            margin: auto;
            display: block;
          }

          .tips {
            font-size: 16px;
            color: #767676;
            line-height: 22px;
            text-align: center;
          }
        }

        .bottomNodata {
          position: fixed;
          bottom: 50px;
          font-weight: 400;
          text-align: center;
          font-size: 0.42667rem;
          color: #fc6f00;
          left: 0;
          right: 0;
          background: #fff;
          line-height: 36px;
          margin-bottom: 5px;

          .tips {
            font-size: 14px;
            color: rgba(105, 105, 105, 1);
          }
        }

      }
    }

    .van-popup {
      background: transparent !important;
    }

    .logincont {
      left: 0;
      top: 0;
      right: 0;
      margin: 0;
      width: 302px;
      height: 172px;
      margin: 0 auto;
      line-height: 20px;
      // border-radius: 50%;
      border-radius: 10px;
      text-align: center;
      background-color: #fff;
      padding: 20px;

      .person_yzm {
        display: flex;
        justify-content: space-between;
        margin-bottom: 30px;

        span {
          font-size: 16px;
          color: #333;
        }
      }

      .person_loginitem {
        display: flex;
        justify-content: space-around;
        margin-bottom: 15px;

        .smscode {
          width: 200px;
          border: none;
          font-size: 14px;
          border-bottom: 1px solid #eee;
          color: #bbb;
          font-weight: 200;
        }

        .sendcode {
          line-height: 20px;
          border-radius: 3px;
          background-color: rgba(62, 151, 252, 1);
          color: rgba(255, 255, 255, 1);
          text-align: center;
          box-shadow: 0px 0px 6px 0px rgba(59, 48, 25, 0.31);
        }

      }

      .person_tip {
        font-size: 12px;
        font-weight: 200;
        color: #bbb;
        text-align: left;
        margin-bottom: 25px;
      }

      .person_sumbit {
        background-color: rgba(244, 197, 105, 1);
        color: rgba(255, 255, 255, 1);
        font-size: 14px;
        text-align: center;
        box-shadow: 0px 0px 6px 0px rgba(59, 48, 25, 0.31);
        width: 100px;
        height: 38px;
      }
    }
  }
</style>
